using System;
using System.Net;
using System.Collections.Generic;
using System.Net.NetworkInformation;

namespace Pscx.Commands.Net
{
    abstract class PingTaskBase
    {
        readonly PingExecutor executor;
        readonly IPHostEntry host;
        
        readonly PingOptions options;

        protected PingTaskBase(PingExecutor executor, IPHostEntry host)
        {
            this.executor = executor;
            this.host = host;

            this.options = new PingOptions(executor.Command.TTL, false);
        }

        public PingExecutor Executor
        {
            get { return executor; }
        }
        public IPHostEntry HostEntry
        {
            get { return host; }
        }

        protected IPAddress[] Addresses
        {
            get
            {
                return executor.Command.AllAddresses.IsPresent ?
                    host.AddressList :
                    new IPAddress[] { host.AddressList[0] };
            }
        }
        protected PingOptions PingOptions
        {
            get { return options;  }
        }
        protected int Timeout
        {
            get { return executor.Command.Timeout; }
        }
        protected int Count
        {
            get { return executor.Command.Count; }
        }
        protected byte[] Buffer
        {
            get { return executor.Command.Buffer; }
        }
    }
}
